<?
	/* RSS - stream reader plugin */	

	// return type of service
	function rss_getType() { return "blogging"; }


	// extra the service- action  line ("ike: "I tweeted on twitter.com")
	function rss_getAction($line) {
		$entry=explode("|",$line);
		return "<a href='?service=rss'><img class='icon' src='".serviceIcon("rss")."'/></a> New item in my <a href='".$entry[4]."'>rss</a> feed";
	}
	
	// extract and return the correct caption
	function rss_getCaption($line) {
		$entry=explode("|",$line);
		return $entry[6];
	}

	// extract and return the correct post
	function rss_getPost($line) {
		$entry=explode("|",$line);
		return $entry[3];
	}

	// extract and return the correct link to the item
	function rss_getLink($line) {
		$entry=explode("|",$line);
		return $entry[5];
	}	

	// display information about us with a link to the profile
	//  -- this is called to display list of services that are linked (admin-functions.php)
	function rss_identify($item) {
		$entry=explode("|",$item);
		return "RSS Feed: <a href='".$entry[3]."'>".$entry[2]."</a>";
	}	


	// get service + profile information
	function rss_addProfile() {
			$serviceID=$_POST['addservice'];
			$username=$_POST['username'];
	
			$rsslink=$username;
			
			writeService($serviceID,$username,$rsslink);
	}

	// download latest items from this service
	function rss_download($serviceid,$filename)  {
		$reader = new XMLReader();
		$reader->open($filename );

			
		set_time_limit(30);


		$count=0;
		
		$itemids=array();
		$continueParsing=true;

		while ($reader->read() && $continueParsing) {
				
				if ($reader->nodeType==XMLREADER::ELEMENT) {

					if ($reader->localName=="item") {
						$guid=null;
						$title=null;
						$mediaurl=null;
						$thumb=null;
						$link=null;
						$pubdate=null;
						$content=null;
						
						while ($reader->read()) {

							if ($reader->name=="guid" && !$guid) {
								$reader->read();
								$guid=$reader->value;
							}

							/*
							if ($reader->localName=="link" && !$link) {
								$reader->read();
								$link=$reader->value;
							}
							*/
							
							if ($reader->localName=="pubDate" && !$pubdate) {
								$reader->read();
								$pubdate=$reader->value;
							}

							if ($reader->name=="title" && !$title) {
								$reader->read();
								$title=$reader->value;
							}
		

							if ($reader->name=="link" && !$link) {
								$reader->read();
								$link=$reader->value;
							}

							if ($reader->name=="description" && !$content) {
								$reader->read();
								$content=$reader->value;
							}

							
							if ($reader->localName=="item") {
								if ($guid) {
								
									$indx=date("YmdHis",strtotime($pubdate));
									
									if (newGuid($guid)) {
										$item[$indx]->title=$title;
										$item[$indx]->post=$content;
										$item[$indx]->link=$link;
										$item[$indx]->pubDate=$pubdate;
										$item[$indx]->guid=$guid;
										$item[$indx]->extra="|".$link."|".$title;
									} else $continueParsing=false;
									
								}
								break;
							}
						}
						
						//print $item[$guid]["title"]." : <img src='".$item[$guid]["media"]."'>";
					}
					set_time_limit(30);
				}
				
		}  
		
		insertEntries($item,"rss",$serviceid);
	}
?>